/*
 *https://leetcode.cn/problems/xor-queries-of-a-subarray/
 *1310. 子数组异或查询
 *medium 吴朝泽 2024.11.30
 *前缀和
*/

#include<bits/stdc++.h>
using namespace std;
class Solution {
public:
    vector<int> xorQueries(vector<int>& arr, vector<vector<int>>& queries) {
        int n = arr.size();
        vector<int> ans;
        int a, b;
        int s[100000] = {0};
        s[0] = 0;
        for(int i = 1; i <= n; ++i)
        {
            s[i] = s[i-1] ^ arr[i-1];   //注意前缀异或和前缀和的区别
        }

        for(auto k : queries)
        {
            a = k[0];
            b = k[1];
            ans.push_back(s[b + 1] ^ s[a]);  
        }
        return ans;
    }
};

/*
XOR(arr[a], arr[a+1], ..., arr[b]) = s[b + 1] ^ s[a]
s[b + 1] ^ s[a] = (arr[0] ^ arr[1] ^ ... ^ arr[b]) ^ (arr[0] ^ arr[1] ^ ... ^ arr[a-1])
                = arr[a] ^ arr[a+1] ^ ... ^ arr[b]
*/ 